import java.util.Arrays;
import java.util.Scanner;

//审题的时候出现错误 注意的是 对数
public class D {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ty[] a = new ty[n + 10];
		for(int i = 1; i <= n; i ++ ) {
			a[i] = new ty();
			a[i].l = sc.nextInt();
			a[i].r = sc.nextInt();
		}
		
		Arrays.sort(a, 1, n + 1);
	
		int ret = 0;
		//二分
		for(int i = 1; i <= n; i ++ ) {
			int x = a[i].r;
			int l = i, r = n + 1;
			while(l + 1 < r) {
				int mid = (l + r) / 2;
				if(a[mid].l <= x)l = mid;
				else r = mid;
			}
			ret += (l - i);
		}
		System.out.print(ret);
	}
}

class ty implements Comparable<ty>{
	int l;
	int r;
	@Override
	public int compareTo(ty o) {
		if(this.l != o.l) {
			return this.l - o.l;
		} else {
			return this.r - o.r;
		}
	}
}
